@echo off
color 0A

echo.
echo -------------------------------------------------------------
echo.      Chemicals Defender Exclusion Tool (FIFA 15 Edition)
echo -------------------------------------------------------------
echo.
echo -------------------------------------------------------------
echo. This Tool Will Automatically Add The Folder It Is Ran From
echo.            As An Exclusion Into Windows Defender
echo.
echo. It Will Also Only Work As Admin, The Next Stage Will Restart
echo.        The Tool To Continue As Admin If This Is Not An 
echo.                    Elevated Session!
echo -------------------------------------------------------------
echo.      The Folder The Exclusion Will be Applied To is: 
echo.                "%~dp0"
echo.
echo.           The Above Should End With \FIFA 15\
echo.
echo.  Please Check You Are Running This From The CORRECT Folder 
echo.                    Before Continuing!
echo -------------------------------------------------------------
echo To Continue and Begin Check if this is an Elevated Session
echo.                Press Any Key To Continue
pause >nul 

whoami /groups | find "S-1-16-12288" >nul
if not %errorlevel%==0 (
echo.
echo ---------------------------------------------------------------	
echo Session Not Elevated! Press Any Key To Restart As Administator!
echo ---------------------------------------------------------------
	pause >nul
	powershell -NoProfile -Command ^
		"Start-Process -FilePath '%~f0' -Verb RunAs"
	exit /b
)

echo --------------------------------------------------------------------------------
echo Session Is Elevated, Press Any Key To Add Exclusion To Folder "%~dp0"
echo --------------------------------------------------------------------------------
pause >nul

PowerShell -NoProfile -ExecutionPolicy Bypass -Command ^
	"Add-MpPreference -ExclusionPath '%~dp0'"

PowerShell -NoProfile -ExecutionPolicy Bypass -Command ^
	"$TCU = (Get-MpPreference).ExclusionPath; if ($TCU -contains '%~dp0') { Write-Host 'Exclusion Applied Successfully!' -ForegroundColor Green; exit 0 } else { Write-Host 'Exclusion Failed!' -ForegroundColor Red; exit 1 }"

echo --------------------------------------------------------------------------------

if errorlevel 1 (
	echo.
	echo WARNING: Defender Exclusion Did Not Verify Correctly!
	echo --------------------------------------------------------------------------------
	powershell -NoProfile -Command ^
  		"$s=Get-Service WinDefend -ErrorAction SilentlyContinue; if($s -and $s.Status -eq 'Running'){Write-Host 'Defender is running' -	ForegroundColor Green}else{Write-Host 'Defender is NOT running' -ForegroundColor Red; exit 1}"
	if %errorlevel%==0 (
    		echo Defender Is Running, Check For Third Party Apps And Report To Devs!
	) else (
    		echo Defender Is Not Running, Third Party AV Likely Installed!
		echo.    EXCLUSION NOT APPLIED, REPORT THIS TO SUPPORT! 
)
echo --------------------------------------------------------------------------------
) else (
	echo Folder "%~dp0" has been added to the Microsoft Defender Exclusion List!
echo.
echo --------------------------------------------------------------------------------
echo Thanks For Using Chemicals Defender Exclusion Tool! To Exit, Just Press Any Key!
echo --------------------------------------------------------------------------------
)
pause >nul